<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="收料单号" prop="receiptMaterialNo">
        <el-input v-model="queryParams.receiptMaterialNo" placeholder="请输入收料单号" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="物料类别" prop="categoryNo">
        <el-select v-model="queryParams.categoryNo" filterable allow-create default-first-option placeholder="供应商名称">
          <el-option v-for="item in wuxia" :key="item.value" :label="item.categoryNo" :value="item.categoryNo">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="物料名称" prop="categoryName">
        <el-input v-model="queryParams.categoryName" placeholder="请输入物料名称" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="供应商名称" prop="supplierName">
        <el-select v-model="queryParams.supplierName" filterable allow-create default-first-option @change="selects"
          placeholder="供应商名称">
          <el-option v-for="item in  xialakuang" :key="item.value" :label="item.supplierName"
            :value="item.supplierName">
          </el-option>
        </el-select>
      </el-form-item>





      <el-form-item label="收料人" prop="materialPerson">
        <el-input v-model="queryParams.materialPerson" placeholder="请输入收料人员" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="收料时间">
        <el-date-picker v-model="materialTime" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['system:info:add']">新增</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['system:info:edit']">修改</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['system:info:remove']">批量删除</el-button>
      </el-col>
      <el-col :span="1.5">



        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['system:info:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="收料单号" align="center" prop="receiptMaterialNo" />
      <el-table-column label="物品摘要" align="center" prop="summary">


      </el-table-column>
      <el-table-column label="仓库名称" align="center" prop="warehouseName" />
      <el-table-column label="仓库区域" align="center" prop="warehouseArea" />
      <el-table-column label="收料人员" align="center" prop="materialPerson" />
      <el-table-column label="收料时间" align="center" prop="materialTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.materialTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="供应商名称" align="center" prop="supplierName" />
      <!-- <el-table-column label="供应商编号" align="center" prop="supplierNo" /> -->
      <el-table-column label="运输单位" align="center" prop="transportUnit" />
      <el-table-column label="车牌号" align="center" prop="carNumber" />
      <el-table-column label="运费" align="center" prop="freight" />
      <!-- <el-table-column label="备注" align="center" prop="comment" /> -->
      <!-- <el-table-column label="项目编号" align="center" prop="projectNo" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" :disabled="jinyong" @click="handleUpdate(scope.row)"
            v-hasPermi="['system:info:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" :disabled="jinyong" @click="handleDelete(scope.row)"
            v-hasPermi="['system:info:remove']">删除</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" :disabled="jinyong" @click="lookOver(scope.row)"
            v-hasPermi="['system:info:lookOver']" >查看</el-button>
          <el-button  size="mini" type="text" icon="el-icon-delete" :disabled="jinyong" @click="storage(scope.row)"
            v-hasPermi="['material:ReceiptMaterial:status']">确认入库</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    
  </div>
</template>

<script>
import { listInfo, getInfo, delInfo, addInfo, updateInfo, supplierDropDown, materialDrop, wonfirmWarehousing, Querying, Xiugai} from "@/api/material/MaterialInfo";

export default {
  name: "Info",
  data() {
    return {
      jinyong:false,
      wuxia: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 收料单信息表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 项目编号时间范围
      daterangeMaterialTime: [],
      // 供应商下拉框
      xialakuang: [],
      materialTime:null,
      // 查询参数
      queryParams: {
        id:null,
        createBy:null,
        pageNum: 1,
        pageSize: 10,
        receiptMaterialNo: null,
        categoryName: null,
        supplierTheme: null,
        supplierName: null,
        materialType: null,
        warehouseName: null,
        warehouseArea: null,
        materialPerson: null,
        materialTime: null,
        projectNo: null,
        categoryNo: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    supplierDropDown(this.queryParams).then(res => {
      for (let i = 0; i < res.rows.length; i++) {
        this.xialakuang = res.rows[i].supplierName;
        this.xialakuang = res.rows
      }
    });
    materialDrop(this.queryParams).then(ok => {
      for (let i = 0; i < ok.rows.length; i++) {
        this.wuxia = ok.rows[i].categoryNo;
        this.wuxia = ok.rows
      }
    })


  },
  methods: {

    selects() {
    },
    superTheme() {
      console.log(111111)
    },
    /** 查询收料单信息列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeMaterialTime && '' != this.daterangeMaterialTime) {
        this.queryParams.params["beginMaterialTime"] = this.daterangeMaterialTime[0];
        this.queryParams.params["endMaterialTime"] = this.daterangeMaterialTime[1];
      }
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        receiptMaterialNo: null,
        supplierTheme: null,
        supplierName: null,
        categoryName: null,
        materialType: null,
        summary: null,
        warehouseName: null,
        warehouseArea: null,
        materialPerson: null,
        materialTime: null,
        supplierNo: null,
        transportUnit: null,
        carNumber: null,
        freight: null,
        categoryNo: null,
        createTime: null,
        createBy: null,
        comment: null,
        projectNo: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeMaterialTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$router.push('/MaterialInfo/MaterialInfoAdd')
      this.reset();
      this.open = true;
      this.title = "添加收料单信息";
      
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      Querying(row.id).then(res=>{
        this.queryParams.createBy =  res.data.createBy
      })
      this.$router.push({path:"/MaterialInfo/MaterialInfoX",query:{id:row.id}})
      // this.reset();
      // const id = row.id || this.ids
      // getInfo(id).then(response => {
      //   this.form = response.data;
      //   this.open = true;
      //   this.title = "修改收料单信息";
      // });
    },
    /** 提交按钮 */
    // submitForm() {
    //   this.$refs["form"].validate(valid => {
    //     if (valid) {
    //       if (this.form.id != null) {
    //         updateInfo(this.form).then(response => {
    //           this.$modal.msgSuccess("修改成功");
    //           this.open = false;
    //           this.getList();
    //         });
    //       } else {
    //         addInfo(this.form).then(response => {
    //           this.$modal.msgSuccess("新增成功");
    //           this.open = false;
    //           this.getList();
    //         });
    //       }
    //     }
    //   });
    // },
    // 查看
    lookOver(row) {
      
      Querying(row.id).then(res=>{
        this.queryParams.createBy =  res.data.createBy
      })
      this.$router.push({path:"/MaterialInfo/MaterialInfoLook",query:{id:row.id}})
      
    },
    /**确认入库*/
    storage(row) {
      wonfirmWarehousing(row.id).then(res=>{
          this.$message({
              type: 'info',
              message: `入库成功`
            });
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除收料单信息编号为"' + ids + '"的数据项？').then(function () {
        return delInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/info/export', {
        ...this.queryParams
      }, `info_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>


<style scoped>
.el-dropdown-link {
  cursor: pointer;
  color: #409EFF;
}

.el-icon-arrow-down {
  font-size: 12px;
}
</style>